package com.digitalchina.lxnsy.activity.old;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputFilter;
import android.text.method.DigitsKeyListener;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.toolkit.RegexpUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/3/7 11:25
 * 修改备注：
 * ================================================
 */
public class EditExpertInfoActivity extends BaseActivity {


    @Bind(R.id.edit_expert_info_edt)
    EditText editExpertInfoEdt;
    @Bind(R.id.edit_expert_info_tv_hint)
    TextView editExpertInfoTvHint;
    private String type = "";

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_edit_expert_info);
        setRightText("保存");
    }

    @Override
    public void initMember() {

        editExpertInfoEdt.setText(getIntent().getSerializableExtra("content").toString());
        //手动设置maxLength为10
        InputFilter[] filters = {new InputFilter.LengthFilter(10)};
        //手动设置maxLength为10
        InputFilter[] filters100 = {new InputFilter.LengthFilter(100)};
        type = (String) getIntent().getSerializableExtra("type");
        switch (type) {
            case "trueName": // 真实姓名
                setTitle("真实姓名");
                editExpertInfoEdt.setHint("请填写真实姓名");
                editExpertInfoEdt.setFilters(filters);
                editExpertInfoTvHint.setText("最多输入10个字符");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "company": // 工作单位
                setTitle("工作单位");
                editExpertInfoEdt.setHint("请填写工作单位");
                editExpertInfoTvHint.setText("请填写真实工作单位");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "addressDetail": // 详细地址
                setTitle("详细地址");
                editExpertInfoEdt.setHint("请填写详细地址");
                editExpertInfoTvHint.setText("请填写您所在单位的详细地址");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "titleNumber": // 专家职称号
                setTitle("专家职称号");
                editExpertInfoEdt.setHint("请填写专家职称号");
                editExpertInfoTvHint.setText("请填写正确的职称号便于审核");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "idCardNo": // 身份证号
                setTitle("修改身份证号");
                editExpertInfoEdt.setHint("请填写身份证号");
                String digitsID = "0123456789xyzXYZ";
                editExpertInfoEdt.setKeyListener(DigitsKeyListener.getInstance(digitsID));
                editExpertInfoTvHint.setText("请填写正确的身份证号便于审核");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "achievement": // 个人成就
                setTitle("修改个人成就");
                //手动设置maxLength为10
                editExpertInfoEdt.setHint("请填写个人成就");
                editExpertInfoEdt.setFilters(filters100);
                editExpertInfoTvHint.setText("请填写真实的个人成就，不超过100个字");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
            case "intro": // 个人简介
                setTitle("个人简介");
                editExpertInfoEdt.setHint("请填写个人简介");
                editExpertInfoTvHint.setText("对自己的身份做出简要介绍");
                editExpertInfoTvHint.setVisibility(View.VISIBLE);
                break;
        }

        editExpertInfoEdt.setSelection(editExpertInfoEdt.getText().length());//将光标移至文字末尾
        editExpertInfoEdt.requestFocus();//获取焦点
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
            }
        };
    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {
        if (StringUtil.isStrEmpty(editExpertInfoEdt.getText().toString())) {
            showToast("请输入内容!");
            return;
        }


        if (type.equals("idCardNo") && !RegexpUtil.isRegexpValidate(editExpertInfoEdt.getText().toString(), RegexpUtil.REGEXP_ID_CARD)) {
            showToast("请输入正确的身份证号码");
            return;
        }

        Intent intent = new Intent();
        intent.putExtra("edit", editExpertInfoEdt.getText().toString());
        intent.putExtra("type", type);
        setResult(RESULT_OK, intent); //intent为A传来的带有Bundle的intent，当然也可以自己定义新的Bundle
        finish();//此处一定要调用finish()方法
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
